from vnpy.app.cta_strategy.backtesting import BacktestingEngine, OptimizationSetting
from vnpy.trader.constant import Interval
from datetime import datetime


if __name__ == "__main__":
    engine = BacktestingEngine()
    engine.set_parameters(
        vt_symbol="BTCUSDT.BINANCE",
        interval=Interval.MINUTE,
        start=datetime(2024, 1, 1),
        end=datetime(2024, 2, 1),
        rate=0.0006,  # 手续费率
        slippage=0.5,  # 滑点
        size=8,  # 合约乘数
        pricetick=0.5,  # 价格跳动
        capital=100000  # 初始资金
    )

    engine.add_strategy(BTCLeveragedNeutralGridStrategy, {
        "grid_step": 100,
        "price_range_low": 30000,
        "price_range_high": 40000,
        "init_volume": 1
    })

    engine.load_data()
    engine.run_backtesting()
    df = engine.calculate_result()
    engine.calculate_statistics()
    engine.show_chart()
